package com.xingfudazi.web.controller.app;

import com.google.common.collect.ImmutableMap;
import com.xingfudazi.app.domain.AppFollowRel;
import com.xingfudazi.app.dto.MemberAvatar;
import com.xingfudazi.app.service.IAppFollowRelService;
import com.xingfudazi.app.service.IAppMemberService;
import com.xingfudazi.common.core.controller.BaseController;
import com.xingfudazi.common.core.domain.Result;
import com.xingfudazi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author YuJiaMing
 * date 2024年07月22日 15:06
 */
@RestController
@RequestMapping("/app/follow-rel")
public class AppFollowRelController extends BaseController {

    @Autowired
    private IAppFollowRelService appFollowRelService;

    @Autowired
    private IAppMemberService appMemberService;


    /**
     * 添加关注
     */
    @PostMapping
    public Result<?> add(@RequestBody AppFollowRel appFollowRel) {
        Long followId = appFollowRel.getFollowId();
        if (followId == null) {
            throw new IllegalArgumentException();
        }
        appFollowRelService.add(appFollowRel);

        return Result.success();
    }


    /**
     * 取消关注
     */
    @DeleteMapping("{followId}")
    public Result<?> delete(@PathVariable Long followId) {
        appFollowRelService.delete(followId);
        return Result.success();
    }


    /**
     * 查询动态列表, 我喜欢的
     */
    @GetMapping("dog/turn")
    public Result<List<MemberAvatar>> dogTurn(@RequestParam(defaultValue = "20") Integer pageSize,
                                           Long lastId, String search,@RequestParam Long nid) {
        List<MemberAvatar> memberAvatarList = appFollowRelService.dogTurn(pageSize, lastId, search,nid);
        return Result.success(memberAvatarList);
    }


    /**
     * 查询动态列表， 互相喜欢的
     */
    @GetMapping("love/turn")
    public Result<List<MemberAvatar>> loveTurn(@RequestParam(defaultValue = "20") Integer pageSize,
                                           Long lastId, String search,@RequestParam Long nid) {
        List<MemberAvatar> memberAvatarList = appFollowRelService.loveTurn(pageSize, lastId, search,nid);
        return Result.success(memberAvatarList);
    }


    @GetMapping("count")
    public Result<Map<String,Long>> count(@RequestParam Long nid) {
        int  dogTurnCount =  this.appFollowRelService.dogTurnCount(nid);
        Long  loveTurn =  this.appFollowRelService.loveTurnCount(nid);
        return Result.success(ImmutableMap.of("dogTurnCount", (long) dogTurnCount,"loveTurn",loveTurn));
    }

}
